package cn.stacey.ssm;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import cn.stacey.spring.ssm.domain.AjaxResponse;
import cn.stacey.spring.ssm.domain.Category;
import cn.stacey.spring.ssm.domain.Post;
import cn.stacey.spring.ssm.service.PostService;

@RunWith(SpringRunner.class)
@ContextConfiguration("/context-anno.xml")
public class testPost {
	@Autowired
	PostService service;
	@Test
	public void test() {
		Post post = new Post();
		post.setTitle("stacey");
		post.setCid(3);
		List<Post> posts = service.search(post);
		for(Post p:posts) {
		System.out.println(p);
		}
		
		
	}
	
	@Test
	public void test1() {
		Post post = new Post();
		post.setTitle("袁诗");
		post.setContent("内容1");
		service.update1(1,post);
		
	}
	
	@Test
	public void test2() {
		Post post = new Post();
		Category c=new Category();
		for(int i=0;i<50;i++) {
			post.setTitle("文章标题"+i);
			post.setContent("文章内容"+i);
			post.setCreated(new Date());
			c.setName("分类"+i);
			post.setCategory(c);
			service.insert(post);
			
		}
	}
		
		
		@Test
		public void test3() {
			AjaxResponse<Post> searchPage = service.searchPage("文章标题", null, null, 1, 10);
				List<Post> posts = searchPage.getData();
				for(Post p:posts) {
					System.out.println(p);
				}
			
		
	}
}
